Online-Academy

Look, Read, Understand, Apply

Menu

Number To Digits

// Java program to find middle digit of number
import java.util.*;
import java.io.*;
class number_to_indi_digits{
    long n;
    public number_to_indi_digits(long nn){
        n = nn;
    }
    public void showDigits(long nn){
        n = nn;
        int i=1;
        int digits = (int)Math.log10(n)+1;//gets number of digits 
        while(i⁢=digits){
            System.out.print((int)(n/Math.pow(10,digits-i))%10+" ");
            ++i;
        }
    }

public static void main(String[] args)
{
    int N = 98562;
    number_to_indi_digits obj = new number_to_indi_digits(N);
    System.out.print("\n"+N+" to Digits: ");
    obj.showDigits(N);
    N = 123;
    System.out.print("\n"+N+" to Digits: ");
    obj.showDigits(N);
}
}